﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoolERP_Common
{
    public class ValueTextItem
    {
        protected object _Value;
        protected string _Text;

        public ValueTextItem(object value)
            : this(value, Convert.ToString(value))
        { }

        public ValueTextItem(object value, string text)
        {
            _Value = value;
            _Text = text;
        }

        public object Value
        {
            get { return _Value; }
        }

        public object Text
        {
            get { return _Text; }
        }

        public override string ToString()
        {
            return _Text;
        }

        public override bool Equals(object obj)
        {
            if (obj is ValueTextItem)
                return object.Equals(((ValueTextItem)obj)._Value, _Value);
            else
            {
                if (obj != null && _Value != null && obj.GetType() == _Value.GetType())
                    return object.Equals(obj, _Value);
                return base.Equals(obj);
            }
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }

    public class ValueTextItem<T> : ValueTextItem
    {
        public ValueTextItem(T value)
            : base(value)
        { }

        public ValueTextItem(T value, string text)
            : base(value, text)
        { }

        public new T Value
        {
            get { return (T)base.Value; }
        }
    }

    public class ValueTextItemComparer : EqualityComparer<ValueTextItem>
    {
        public override bool Equals(ValueTextItem x, ValueTextItem y)
        {
            return object.Equals(x, y);
        }

        public override int GetHashCode(ValueTextItem obj)
        {
            return base.GetHashCode();
        }
    }
}
